package com.bjpowernode.ba03;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Autowired:Spring提供的注解,实现引用数据类型
 * spring中通过注解给引用数据类型赋值,使用的是自动注入的原理,支持byName和byType,前提是宁一个类也需要使用@Component
 * @Autowired:默认使用的是byType自动注入
 * 位置:1)在属性的上面,无需set方法推荐使用
 *     2)在set方法上面
 */
@Component(value = "myStudent03")
public class Student {
    @Value("张飞")
    private String name;
    @Value("29")
    private Integer age;

    @Autowired
    private School school;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public School getSchool() {
        return school;
    }

    public void setSchool(School school) {
        this.school = school;
    }

    public Student() {
    }

    public Student(String name, Integer age, School school) {
        this.name = name;
        this.age = age;
        this.school = school;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", school=" + school +
                '}';
    }
}
